using System;
using System.Text;

namespace XHTMLPoink
{

    public static class XHTMLErrorGen
    {

        public static string GenerateErrorPage(int ErrorNumber, string WittierDesc, string ProperDesc)
        {
            XHTMLTemplate xtErrorDoc = new XHTMLTemplate(XHTMLTemplate.FilesDir + "/templates/error.xhtml.template");

            xtErrorDoc.SetVariable("Error Number", ErrorNumber.ToString());
            xtErrorDoc.SetVariable("Description 1", ProperDesc);
            xtErrorDoc.SetVariable("Description 2", WittierDesc);

            xtErrorDoc.SetVariable("Image Filename", ConjureImageFilename(ErrorNumber));
            xtErrorDoc.SetVariable("Image Alt", ConjureImageAlt(ErrorNumber));

            return xtErrorDoc.GetSection("Standard Error");
        }

        private static string ConjureImageFilename(int ErrNum)
        {
            if (ErrNum.ToString().Length == 3)
            {
                switch (ErrNum.ToString().Substring(0, 1))
                {
                    case "4":
                        return "/files/4xx.jpg";
                        break;
                    case "5":
                        return "/files/5xx.jpg";
                        break;
                    default:
                        return "/files/0xx.jpg";
                        break;
                }
            }
            else
            {
                return "/files/0xx.jpg";
            }
        }

        private static string ConjureImageAlt(int ErrNum)
        {
            if (ErrNum.ToString().Length == 3)
            {
                switch (ErrNum.ToString().Substring(0, 1))
                {
                    case "4":
                        return "Pokemon, Doom-3 style ^.^";
                        break;
                    case "5":
                        return "CAPTIVITY -- It could be worse.  (Three cats looking intently at a mouse inside its cage)";
                        break;
                    default:
                        return "Cat with wide eyes sitting neatly on an electronic keyboard (labelled 'Odyssey'), with a starry background and nothing else in view..";
                        break;
                }
            }
            else
            {
                return "Cat with wide eyes sitting neatly on an electronic keyboard (labelled 'Odyssey'), with a starry background and nothing else in view..";
            }
        }

    }

}
